import 'package:flutter/material.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBEngineer/YBBaseRouter/YBApplication.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBEngineer/YBBaseRouter/YBNavigator.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBColor/YBColor.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBCommonToast/YBCommonToastPage.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBTextStyle/YBTextStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/yb_chinese_text/yb_chinese_text.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBMineModule/YBQiYePersonPage/YBNumberManagerEditingSubPage.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBMineModule/YBQiYePersonPage/YBNumberManagerProvider/YBNumberManagerEventBus.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBNetWorkModule/YBBaseMineNetWork/YBBaseMineNetWork.dart';



class YBNumberManagerEditingPage extends StatefulWidget {

  final String xingMingStr;
  final String telPhoneStr;
  final String wechatStr;
  final String emailStr;
  final String departStr;
  final String zhiweiStr;
  final String memberCode;
  final String memberType;

  const YBNumberManagerEditingPage({Key key, this.xingMingStr, this.telPhoneStr, this.wechatStr, this.emailStr, this.departStr, this.zhiweiStr,this.memberType,this.memberCode}) : super(key: key);

  @override
  _YBNumberManagerEditingPageState createState() => _YBNumberManagerEditingPageState(xingMingStr: xingMingStr,telPhoneStr: telPhoneStr,wechatStr: wechatStr,emailStr: emailStr,departStr: departStr,zhiweiStr: zhiweiStr,memberCode: memberCode,memberType: memberType);
}

class _YBNumberManagerEditingPageState extends State<YBNumberManagerEditingPage> {

  final String xingMingStr;
  final String telPhoneStr;
  final String wechatStr;
  final String emailStr;
  final String departStr;
  final String zhiweiStr;
  final String memberCode;
  final String memberType;


  _YBNumberManagerEditingPageState({this.xingMingStr, this.telPhoneStr, this.wechatStr, this.emailStr, this.departStr, this.zhiweiStr,this.memberCode,this.memberType});

  String _xingMingInfo;
  String _telPhoneInfo;
  String _wechatInfo;
  String _emilInfo;
  String _departInfo;
  String _zhiweiInfo;

  @override
  void initState() {
    super.initState();
    _xingMingInfo = xingMingStr;
    _telPhoneInfo = telPhoneStr;
    _wechatInfo = wechatStr;
    _emilInfo = emailStr;
    _departInfo = departStr;
    _zhiweiInfo = zhiweiStr;
    numberManagerEventBus.on<YBNumberManagerEventBus>().listen((event) {
      print('----${event.content}------${event.title}');
       if (event.title.contains('姓名')){
           print('----${event.content}');
           setState(() {
             _xingMingInfo = event.content;
           });
       }else if (event.title.contains('电话')){
         print('----${event.content}');
         setState(() {
           _telPhoneInfo = event.content;
         });
       }else if (event.title.contains('微信号')){
         print('----${event.content}');
         setState(() {
           _wechatInfo = event.content;
         });
       }else if (event.title.contains('邮箱')){
         print('----${event.content}');
         setState(() {
           _emilInfo = event.content;
         });
       }else if (event.title.contains('部门')){
         print('----${event.content}');
         setState(() {
           _departInfo = event.content;
         });
       }else if (event.title.contains('职位')){
         print('----${event.content}');
         setState(() {
           _zhiweiInfo = event.content;
         });
       }
    });
  }


  @override
  Widget build(BuildContext context) {



    Widget memberTypeWidget;
    if (int.parse(memberType) != 1){
       memberTypeWidget = Container(
         child: InkWell(
           child: Container(
               height: YBTextStyle.adapterSize44,
               color: YBColor.white,
               child: Center(
                 child: Text(YBChineseText.mineDelegateTitle,style: YBTextStyle.TextStyle18181814Medium,),
               )
           ),
           onTap: () async {
             _delNumber(memberCode);
           },
         ),
       );
    } else {
      memberTypeWidget = Container();
    }

    return Container(
      child: Scaffold(
        appBar: AppBar(
          elevation: 0,
          title: Text(YBChineseText.mineEditerNumberTitle,style: YBTextStyle.TextStyle30313320Medium),
        ),
        body:SingleChildScrollView(
          child: Column(
            children: [
              //
              Container(
                child: InkWell(
                  child: YBNumberManagerEditingSubPage(titleStr:YBChineseText.mineXingMingTitle,subTitleStr:_xingMingInfo??"",),
                  onTap: () async {
                    YBApplication.router.navigateTo(context, '/mine/mineQiYePersonPage/mineNumberManangerPage/mineNumberManangerEditingPage/mineNumberManangerShuXingEditingPage?titleHeader=${Uri.encodeComponent(YBChineseText.mineXingMingTitle)}&&contentTitle=${Uri.encodeComponent(xingMingStr)}&&memberCode=$memberCode');
                  },
                ),
              ),
              Container(
                child: InkWell(
                  child: YBNumberManagerEditingSubPage(titleStr:YBChineseText.workTaiDianHuaTitle,subTitleStr:_telPhoneInfo??"",),
                  onTap: () async {
                    YBApplication.router.navigateTo(context, '/mine/mineQiYePersonPage/mineNumberManangerPage/mineNumberManangerEditingPage/mineNumberManangerShuXingEditingPage?titleHeader=${Uri.encodeComponent(YBChineseText.workTaiDianHuaTitle)}&&contentTitle=$telPhoneStr&&memberCode=$memberCode');
                  },
                ),
              ),
              Container(
                child: InkWell(
                  child: YBNumberManagerEditingSubPage(titleStr:YBChineseText.mineWeChatHaoTitle,subTitleStr:_wechatInfo??"",),
                  onTap: () async {
                    YBApplication.router.navigateTo(context, '/mine/mineQiYePersonPage/mineNumberManangerPage/mineNumberManangerEditingPage/mineNumberManangerShuXingEditingPage?titleHeader=${Uri.encodeComponent(YBChineseText.mineWeChatHaoTitle)}&&contentTitle=$wechatStr&&memberCode=$memberCode');
                  },
                ),
              ),
              Container(
                child: InkWell(
                  child: YBNumberManagerEditingSubPage(titleStr:YBChineseText.mineEmailTitle,subTitleStr:_emilInfo??"",),
                  onTap: () async {
                    YBApplication.router.navigateTo(context, '/mine/mineQiYePersonPage/mineNumberManangerPage/mineNumberManangerEditingPage/mineNumberManangerShuXingEditingPage?titleHeader=${Uri.encodeComponent(YBChineseText.mineEmailTitle)}&&contentTitle=$emailStr&&memberCode=$memberCode');
                  },
                ),
              ),
              Container(
                height: YBTextStyle.adapterSize8,
              ),
              Container(
                child: InkWell(
                  child: YBNumberManagerEditingSubPage(titleStr:YBChineseText.mineBuMenTitle,subTitleStr:_departInfo??"",),
                  onTap: () async {
                    YBApplication.router.navigateTo(context, '/mine/mineQiYePersonPage/mineNumberManangerPage/mineNumberManangerEditingPage/mineNumberManangerShuXingEditingPage?titleHeader=${Uri.encodeComponent(YBChineseText.mineBuMenTitle)}&&contentTitle=${Uri.encodeComponent(departStr)}&&memberCode=$memberCode');
                  },
                ),
              ),
              Container(
                child: InkWell(
                  child: YBNumberManagerEditingSubPage(titleStr:YBChineseText.mineziWeiTitle,subTitleStr:_zhiweiInfo??"",),
                  onTap: () async {
                    YBApplication.router.navigateTo(context, '/mine/mineQiYePersonPage/mineNumberManangerPage/mineNumberManangerEditingPage/mineNumberManangerShuXingEditingPage?titleHeader=${Uri.encodeComponent(YBChineseText.mineziWeiTitle)}&&contentTitle=${Uri.encodeComponent(zhiweiStr)}&&memberCode=$memberCode');
                  },
                ),
              ),
              Container(
                height: YBTextStyle.adapterSize20,
              ),
              memberTypeWidget,
            ],
          ),
        ),
      ),
    );
  }

  void _delNumber(String memberCode){
    YBMineNetWork.mineDelZuZhiNumberManagerData({
      "memberCode":memberCode,
      "sysCode":"xg_youbang",
    },success: (data){
      bool dataBool = data is bool;
      if (dataBool ==  true){
        YBToast.showToastInfo('删除成功');
        YBNavigatorUtil.goBack(context);
      }
    },fail: (error){
      print('--error--$error---');
    });
  }

}
